﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace ICeFramework.Win.UI.Base
{
    public class UserControlBase : UserControl
    {

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            switch (m.Msg)
            {
                case 0x0084: // WM_NCHITTEST  
                    Point p = PointToClient(new Point((int)m.LParam));
                    if (!HitTest(p))
                    {
                        m.Result = new IntPtr(-1); // HTTRANSPARENT  
                        return;
                    }
                    break;
            }
        }
        public virtual bool HitTest(Point p)
        {
            return true;
        }

        public bool IsContained(Point point, Rectangle rectangle)
        {
            return ((point.X > rectangle.X && point.X < rectangle.X + rectangle.Width) &&
                    (point.Y > rectangle.Y && point.Y < rectangle.Y + rectangle.Height));
        }
    }
}
